package com.xstech.library.utils;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.json.JSONException;
import org.json.JSONObject;

public class LogUtils {
    public static final String LOGTAG = "custom";
    public static boolean debugEnabled;

    public static void printJson(String tag, String message) {
        try {
            JSONObject json = new JSONObject(message);
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            String prettyJson = gson.toJson(json);
            Log.d(tag, "\n" + prettyJson);
        } catch (JSONException e) {
            Log.e(tag, "Invalid JSON: " + message);
        }
    }

    // 打印格式化的 Bean（Java 对象）
    public static void bean(String tag, Object object) {
        try {
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            String formattedJson = gson.toJson(object);
            Log.d(tag, "\n" + formattedJson);
        } catch (Exception e) {
            Log.e(tag, "Invalid Object: " + object);
        }
    }
}
